package com.market.plus.core.mapping;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;

import com.googlecode.simpleobjectassembler.converter.AbstractObjectConverter;
import com.market.plus.core.domain.AlbumType;
import com.market.plus.core.exception.MarketRuntimeException;
import com.market.plus.core.exception.UnsupportTypeException;

@Component
public class IntegerToAlbumTypeConvert extends AbstractObjectConverter<Integer, AlbumType> {

   private static final Logger LOG = Logger.getLogger(IntegerToAlbumTypeConvert.class);

   @Override
   public void convert(Integer sourceObject, AlbumType destinationObject) {
      try {
         destinationObject = AlbumType.getAlbumType(sourceObject.intValue());
      }
      catch (UnsupportTypeException e) {
         LOG.error(e);
      }
   }

   @Override
   public AlbumType createDestinationObject(Integer sourceObject) {
      try {
         return AlbumType.getAlbumType(sourceObject.intValue());
      }
      catch (UnsupportTypeException e) {
         LOG.error(e);
         throw new MarketRuntimeException(e.getMessage());
      }
   }
}
